#include <bits/stdc++.h>

using namespace std;

int main() {
    int row, col;
    cin >> row;
    cin.ignore();
    cin >> col;
    cin.ignore();
    map<char, int> char_map;
    vector<vector<int>> char_matrix;
    for (int i = 0; i <row; ++i) {
        vector<int> line;
        char tmp;
        while(cin.peek() != '\n') {
            if (cin.peek() == ',') {
                cin.ignore();
            } else {
                tmp = cin.get();
                if (char_map.find(tmp) != char_map.end()) {
                    line.push_back(char_map[tmp]);
                } else {
                    if (char_map.size() != 0) {
                        char_map[tmp] = 1;
                    } else {
                        char_map[tmp] = 0;
                    }
                    line.push_back(char_map[tmp]);
                }
            }
        }
        cin.ignore();
        char_matrix.push_back(line);
    }

    vector<int> res;
    for (auto line : char_matrix) {
        int sum = accumulate(line.begin(), line.end(), 0);
        if (sum > line.size()/2) {
            res.push_back(sum);
        } else {
            res.push_back(line.size()-sum);
        }
    }
    for (int i = 0; i < col; ++i) {
        int sum = 0;
        for (int j = 0; j < row; ++j) {
            sum += char_matrix[j][i];
        }
        if (sum > row/2) {
            res.push_back(sum);
        } else {
            res.push_back(row - sum);
        }
    }
    cout << (*max_element(res.begin(), res.end()));
}